#include "transmit_task.h"
#include "stm32f4xx_hal.h"

xQueueHandle CAN1_data_Queue;
extern CAN_HandleTypeDef hcan1;

static void CAN1Transmit(CAN1_Data_t data);

int transmit_d;
BaseType_t sendStatus;
void transmit_Task( void const*pvParameters )
{
	CAN1_Data_t sent;
	
	
	for( ;; )
	{
		transmit_d++;
		sendStatus = xQueueReceive(CAN1_data_Queue, &sent, portMAX_DELAY );
		if( sendStatus == pdPASS )
		{
			CAN1Transmit(sent);
		}
	} 
}

static void CAN1Transmit(CAN1_Data_t data)
{
	CAN_TxHeaderTypeDef  tx_message;
	uint8_t              can_send_data[8];
	
    uint32_t send_mail_box;
    tx_message.StdId = data.stdid;
    tx_message.IDE = CAN_ID_STD;
    tx_message.RTR = CAN_RTR_DATA;
    tx_message.DLC = 0x08;
    can_send_data[0] = data.data[0];
    can_send_data[1] = data.data[1];
    can_send_data[2] = data.data[2];
    can_send_data[3] = data.data[3];
    can_send_data[4] = data.data[4];
    can_send_data[5] = data.data[5];
    can_send_data[6] = data.data[6];
    can_send_data[7] = data.data[7];
    HAL_CAN_AddTxMessage(&hcan1, &tx_message, can_send_data, &send_mail_box);
}
